import 'package:elephantgas/widget/myappbar.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class OrderDetailPage extends StatefulWidget {
  @override
  _MsgState createState() => _MsgState();
}

class _MsgState extends State<OrderDetailPage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xFFF7F7F7),
      appBar: MyAppBar(context: context, title: '订单详情'),
      body: SingleChildScrollView(child: _content()),
    );
  }

  Widget _buildDriverInfo() {
    return Container(
      margin: EdgeInsets.only(left: 12, right: 12, top: 12),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(5)),
      child: Column(
        children: [
          _item('物流公司', '诸城捷通物流有限公司'),
          _item('车牌号', '诸城捷通物流有限公司'),
          _item('司机姓名', '诸城捷通物流有限公司'),
          _item('司机电话', '诸城捷通物流有限公司'),
        ],
      ),
    );
  }

  Widget _buildStation() {
    return Container(
      margin: EdgeInsets.only(left: 12, right: 12, top: 12),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(5)),
      child: Column(
        children: [
          _item('加气站名称', '诸城捷通物流有限公司'),
          _item('收银员姓名', '诸城捷通物流有限公司'),
        ],
      ),
    );
  }

  Widget _buildGas() {
    return Container(
      margin: EdgeInsets.only(left: 12, right: 12, top: 12),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(5)),
      child: Column(
        children: [
          _item('加气量(公斤)', '诸城捷通物流有限公司'),
          _item('平台挂牌价(元/公斤)', '诸城捷通物流有限公司'),
          _item('平台结算价(元/公斤)', '诸城捷通物流有限公司'),
          _item('总价', '诸城捷通物流有限公司'),
          _item1('优惠金额', '-￥20'),
          _item2('', '￥362'),
        ],
      ),
    );
  }

  Widget _buildOrder() {
    return Container(
      margin: EdgeInsets.only(left: 12, right: 12, top: 12),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(5)),
      child: Column(
        children: [
          _item('创建时间', '诸城捷通物流有限公司'),
          _item('付款时间', '诸城捷通物流有限公司'),
          _item('支付方式', '诸城捷通物流有限公司'),
        ],
      ),
    );
  }

  Widget _item2(key, value) {
    return Container(
      height: 50,
      margin: EdgeInsets.only(left: 15, right: 12),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                key,
                style: TextStyle(color: Color(0xFF999999), fontSize: 16.sp),
              ),
              Row(
                children: [
                  Text(
                    '小计',
                    style: TextStyle(color: Color(0xFF999999), fontSize: 16.sp),
                  ),
                  SizedBox(
                    width: 7.5,
                  ),
                  Text(
                    value,
                    style: TextStyle(color: Color(0xFFFE3E1C), fontSize: 16.sp),
                  ),
                ],
              ),
            ],
          )
        ],
      ),
    );
  }

  Widget _item1(key, value) {
    return Column(
      children: [
        Container(
          height: 50,
          alignment: Alignment.center,
          margin: EdgeInsets.only(left: 15, right: 12),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(
                    key,
                    style: TextStyle(color: Color(0xFF999999), fontSize: 16.sp),
                  ),
                  Text(
                    value,
                    style: TextStyle(color: Color(0xFFFE3E1C), fontSize: 16.sp),
                  ),
                ],
              )
            ],
          ),
        ),
        Container(
          height: 0.5,
          color: Color(0xFFEDEDED),
        )
      ],
    );
  }

  Widget _item(key, value) {
    return Column(
      children: [
        Container(
          height: 50,
          alignment: Alignment.center,
          margin: EdgeInsets.only(left: 15, right: 12),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(
                    key,
                    style: TextStyle(color: Color(0xFF999999), fontSize: 16.sp),
                  ),
                  Text(
                    value,
                    style: TextStyle(color: Color(0xFF333333), fontSize: 16.sp),
                  ),
                ],
              )
            ],
          ),
        ),
        Container(
          height: 0.5,
          color: Color(0xFFEDEDED),
        )
      ],
    );
  }

  Widget topInfo(int status) {
    int color1, color2;
    String statusName = '未知';
    if (status == 0) {
      color1 = 0xFFFEA01A;
      color2 = 0xFFFFCC31;
      statusName = '待支付';
    } else if (status == 1) {
      color1 = 0xFF245CDC;
      color2 = 0xFF2384E7;
      statusName = '已支付';
    } else if (status == 2) {
      color1 = 0xFF999999;
      color2 = 0xFFCCCCCC;
      statusName = '已取消';
    }
    return Container(
      height: 50,
      margin: EdgeInsets.only(left: 12, right: 12, top: 11.5),
      padding: EdgeInsets.only(left: 16, right: 16.5),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(5),
          gradient: LinearGradient(
              begin: Alignment.centerLeft,
              end: Alignment.centerRight,
              colors: [Color(color1), Color(color2)])),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Text(
            '订单编号：1054584215541',
            style: TextStyle(color: Colors.white, fontSize: 14.sp),
          ),
          Text(
            statusName,
            style: TextStyle(color: Colors.white, fontSize: 14.sp),
          ),
        ],
      ),
    );
  }

  Widget topInfo1() {
    return Container(
      height: 50,
      margin: EdgeInsets.only(left: 12, right: 12, top: 11.5),
      padding: EdgeInsets.only(left: 16, right: 16.5),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(5),
          gradient: LinearGradient(
              begin: Alignment.centerLeft,
              end: Alignment.centerRight,
              colors: [Color(0xFF245CDC), Color(0xFF2384E7)])),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Text(
            '订单编号：1054584215541',
            style: TextStyle(color: Colors.white, fontSize: 14.sp),
          ),
          Text(
            '已支付',
            style: TextStyle(color: Colors.white, fontSize: 14.sp),
          ),
        ],
      ),
    );
  }

  Widget topInfo2() {
    return Container(
      height: 50,
      margin: EdgeInsets.only(left: 12, right: 12, top: 11.5),
      padding: EdgeInsets.only(left: 16, right: 16.5),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(5),
          gradient: LinearGradient(
              begin: Alignment.centerLeft,
              end: Alignment.centerRight,
              colors: [Color(0xFF245CDC), Color(0xFF2384E7)])),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Text(
            '订单编号：1054584215541',
            style: TextStyle(color: Colors.white, fontSize: 14.sp),
          ),
          Text(
            '已支付',
            style: TextStyle(color: Colors.white, fontSize: 14.sp),
          ),
        ],
      ),
    );
  }

  Widget _tip() {
    return Container(
      margin: EdgeInsets.only(top: 18, left: 12),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            '优惠说明',
            style: TextStyle(color: Color(0xFF333333), fontSize: 12.sp),
          ),
          SizedBox(
            height: 8.5,
          ),
          Text(
            '单车单日加注量≤600公斤按平台结算价享受优惠；超出600公斤\n部分按平台挂牌价结算',
            style: TextStyle(color: Color(0xFF666666), fontSize: 12.sp),
          ),
          SizedBox(
            height: 22.5,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                '对此订单有疑问？请联系4000165388',
                style: TextStyle(color: Color(0xFF999999)),
              )
            ],
          ),
          SizedBox(
            height: 17,
          ),
        ],
      ),
    );
  }

  Widget _content() {
    return Container(
      child: Column(
        children: [
          topInfo(1),
          _buildDriverInfo(),
          _buildStation(),
          _buildGas(),
          _buildOrder(),
          _tip()
        ],
      ),
    );
  }
}
